.SUFFICES: .o .c

#CC = gcc
#CFLAGS = -O3 -mno-app-regs -Wa,-xarch=v8plusa -W -Wall

CFLAGS_GCC = -DSIMICS -O3 -mno-app-regs -Wa,-xarch=v8plusa -W -Wall -I/p//multifacet/projects/ecperf/multifacet/workloads/magic-call

CC = /opt/SUNWspro/bin/cc
GCC = /s/std/bin/gcc
CFLAGS = -DSIMICS -g -xO2 -xtarget=ultra2 -xarch=v8plusa -xregs=no%appl -w -I/p//multifacet/projects/ecperf/multifacet/workloads/magic-call

# My version of gdb isn't MP-capable, so I debug using dbx and code
# produced by cc.

CFILES = pthread_tatas.c \
        pthread_hbo.c \
        pthread_rh.c \
        pthread_profile.c \
        pthread_transactional.c \
	tas.c \
	tas_exp.c \
	mcs_plain.c \
	clh_plain.c \
	hbo.c \
	hbo_gt.c \
	hbo_gt_fair.c \
	atomic_ops.c \
	rh.c \
	time_test.c \
	#node_id.c

OFILES = pthread_tatas.o \
	pthread_hbo.o \
	pthread_rh.o \
        pthread_profile.o \
        pthread_transactional.o \
	tas.o \
	tas_exp.o \
	mcs_plain.o \
	clh_plain.o \
	atomic_ops.o \
	asm_utils.o \
	hbo.o \
	hbo_gt.o \
	rh.o \
	hbo_gt_fair.o \

HFILES = tas.h \
	tas_exp.h \
	mcs.h \
	clh.h \
	rh.h \
	hbo.h \
	hbo_gt.h \
	hbo_gt_fair.h \
	main.h \
	inline.h \
	atomic_ops.h \
	atomic_op_bodies.h \
	wildfire.h \
	asm_utils.h \

.c.o:
	$(GCC) -c $(CFLAGS_GCC) $*.c

#ALL_PROGS = libparmacs_locks.a time_test
#ALL_PROGS = libparmacs_locks.a
ALL_PROGS = libparmacs_locks.so time_test

RM = rm
AR = ar
RANLIB = ranlib
TOUCH = touch

all: $(ALL_PROGS)

libparmacs_locks.a: $(OFILES)
	$(RM) -f $@
	$(AR) -r $@ $(OFILES)
	$(RANLIB) $@

libparmacs_locks.so: $(OFILES)
	$(RM) -f $@
	$(CC) -G -o $@ $(OFILES)

time_test: $(OFILES) time_test.o atomic_ops.o asm_utils.o
	$(GCC) -o time_test $(CFLAGS) \
		$(OFILES) time_test.o -lpthread

time_test.s: time_test.c
	$(CC) -S -fverbose-asm $(CFLAGS) time_test.c

atomic_ops.o: atomic_ops.c
	gcc -c $(CFLAGS_GCC) atomic_ops.c

hbo_gt.o: hbo_gt.c
	gcc -c $(CFLAGS_GCC) hbo_gt.c

pthread_hbo.o: pthread_hbo.c
	gcc -c $(CFLAGS_GCC) pthread_hbo.c

pthread_profile.o: pthread_profile.c
	gcc -c $(CFLAGS_GCC) pthread_profile.c

pthread_transactional.o: pthread_transactional.c
	$(GCC) -c $(CFLAGS_GCC) pthread_transactional.c

hbo.o: hbo.c
	gcc -c $(CFLAGS_GCC) hbo.c

rh.o:  rh.c
	gcc -c $(CFLAGS_GCC) rh.c

node_id.o: node_id.c
	gcc -c $(CFLAGS_GCC) node_id.c

node_id: node_id.o
	gcc -o node_id $(CFLAGS_GCC) node_id.o

asm_utils.o: asm_utils.s
	$(CC) -c $(CFLAGS) asm_utils.s

Scott_test: test.c atomic_ops.o
	gcc -o test -g $(CFLAGS_GCC) test.c atomic_ops.o

test: test.c
	gcc -o test -g $(CFLAGS_GCC) test.c -lpthread -lthread

sources:
	@echo $(CFILES) $(HFILES)

clean:
	rm *.o $(ALL_PROGS)

tags:
	etags $(CFILES) $(HFILES) > TAGS

depend:
	echo '# DO NOT EDIT THIS FILE -- it is automatically generated' \
		> makefile.dep
	echo '' >> makefile.dep
	gcc -M $(CFILES) >> makefile.dep

include makefile.dep
